package top.luo.mycat.business;

import top.luo.mycat.server.HttpProtocolUtils;
import top.luo.mycat.server.HttpServlet;
import top.luo.mycat.server.Request;
import top.luo.mycat.server.Response;

import java.io.IOException;

/**
 * @author luo
 * @date 2021-03-19 12:00
 */
public class MyServlet extends HttpServlet {

    @Override
    public void doGet(Request request, Response response) {
        try {
            Thread.sleep(1000000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String content = "<h1>hello servlet: get method</h1>";
        try {
            response.output(HttpProtocolUtils.getHttpHeaderOk(content.getBytes().length) + content);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void doPost(Request request, Response response) {
        String content = "<h1>hello servlet: post method</h1>";
        try {
            response.output(HttpProtocolUtils.getHttpHeaderOk(content.getBytes().length) + content);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void init() throws Exception {

    }

    @Override
    public void destory() throws Exception {

    }

}
